% get Ti from txt
% 1--Time[s], 
% 2--rho(poloidal flux), 3 Z[m](relative to the equatorial plane), 
% 4--Ti[eV], 
% 5--Ti_error[eV],6 $\Delta$Vt[km/s],7 $\Delta$Vt_error[km/s]
clear;
dt=0.05;
for shot= 142616:142646
    filename=['./Ti/',num2str(shot),'_ArgonWline.txt']
    if exist(filename, 'file')
        data=importdata(filename);
        data=data.data;
        t_list=data(:,1);
        rho_list=data(:,2);
        Ti_list=data(:,4);
        Ti_error_list=data(:,5);
        for t=[3.5,5,6,8]
                ind=(t_list>t-dt)&(t_list<t+dt);
                time=t_list(ind);
                rho=rho_list(ind);
                Ti=Ti_list(ind)/1.e3;
                Ti_error=Ti_error_list(ind)/1.e3;
                save(['./Ti/Ti_',num2str(shot),'_',num2str(t),'.mat'],'time','rho','Ti','Ti_error')
        end
    end
end

figure;
subplot(2,1,1)
t=6;
for shot = 142616:142637
    filename = ['./Ti/Ti_',num2str(shot),'_',num2str(t),'.mat'];
    if exist(filename, 'file')
            load(filename)
            errorbar(rho,Ti,Ti_error,'DisplayName',['Ti_',num2str(shot),'_',num2str(t)]);
            hold on;
    end
end
xlabel('\rho')
ylabel('Ti(keV)')